#include <iostream>
#include <algorithm>
#include <string>
#include <cstdio>
#include <vector>
#include <stack>
#include <queue>
#include <set>
using namespace std;
class Solution
{
public:
    int equalSubstring(string s, string t, int maxCost)
    {
        vector<int> arr(s.size());
        for (int i = 0; i < arr.size(); ++i)
            arr[i] = (s[i] - t[i] > 0) ? (s[i] - t[i]) : (t[i] - s[i]);
        int i = 0, j = 0, cnt = maxCost, ans = 0;
        while (j < arr.size() && cnt - arr[j] >= 0)
            cnt -= arr[j++];
        //[i,j)
        ans = j - i;
        while (j < arr.size())
        {
            cnt += arr[i++];
            while (j < arr.size() && cnt - arr[j] >= 0)
                cnt -= arr[j++];
            ans = max(j - i, ans);
        }
        return ans;
    }
};